<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>画布</title>
    <script type="text/javascript">
        function load() {
            let c = document.getElementById('myCanvas');
            let context = c.getContext('2d');

            context.fillStyle = '#ff00ff';
            context.fillRect(50, 25, 100, 50);
        }

        function checkSupport() {
            let c = document.getElementById('myCanvas');
            if (c.getContext) {
                console.log('support canvas!');
                return true;
            } else {
                console.log('not support canvas!');
                return false;
            }
        }

        window.onload = function () {
            if (checkSupport()) {
                load();
            }
        }
    </script>
</head>

<body>
    <canvas id="myCanvas" style="border: 1px solid #000000" width="800" height="450">
        你的浏览器不支持canvas元素！
    </canvas>
</body>

</html>